import java.util.Scanner;
import java.util.*;
public class Main {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[][] map = new int[n+1][n+1];
        for(int i = 1;i <= n;i++) {
            for(int j = 1;j <= n;j++) {
                map[i][j] = in.nextInt();
            }
        }
        int[][] dp = new int[n+1][n+1];

        for(int i = 1;i <= n;i++) {
            for(int j = 1;j <= n;j++) {
                if(dp[i-1][j] == 0) dp[i][j] = dp[i][j-1] + map[i][j];
                else if(dp[i][j-1] == 0) dp[i][j] = dp[i-1][j] + map[i][j];
                else dp[i][j] = Math.min(dp[i-1][j],dp[i][j-1]) + map[i][j];
            }
        }
        System.out.println(dp[n][n]);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[][] map = new int[n+1][n+1];
        int j = 1,k = 1;
        while(j != 0 && k != 0) {
            j = in.nextInt();
            k = in.nextInt();
            map[j][k] = in.nextInt();
        }

    }

    public static int max(int[][] a) {
        int n = a.length;
        int[][] dp = new int[n+1][n+1];

        for(int i = 1;i <= n;i++) {
            for(int j = 1;j <= n;j++) {
                dp[i][j] = Math.max(dp[i-1][j],dp[i][j-1]) + a[i-1][j-1];

            }
        }
        return 0;
    }
}
